package com.sirui.jpa.repository;

import com.sirui.jpa.model.JpaStudent;
import com.sirui.jpa.model.QueryObj;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
 * 数据操作层
 * 创建时间	2017年7月25日
 *
 * @author linson
 */
public interface StudentRepository extends JpaRepository<JpaStudent, String>, JpaSpecificationExecutor<JpaStudent> {
    @Query("select j from JpaStudent j where j.age = ?1")
    JpaStudent findByAgeEquals(Integer age);

    @Query(value = "select s,c from JpaStudent s,JpaClass c where s.jpaClass.id =c.id")
    List<Object[]> findAllInfo();

    @Query(value = "select s.name as name,c.className as className from JpaStudent s,JpaClass c where s.jpaClass.id =c.id")
    List<Map<String, Object>> findAllInfo1();

    @Query(value = "select s.name as name,c.className as className from JpaStudent s,JpaClass c where s.jpaClass.id =c.id")
    Page<List<Map<String, Object>>> findAllInfo2(Pageable pageable);

    @Query(value = "select new com.sirui.jpa.model.QueryObj(c,s)  from JpaStudent s,JpaClass c where s.jpaClass.id =c.id")
    List<QueryObj> findAllInfo3();
}
